package com.atguigu.linklist;

public class SingleLinkListDemo {
    public static void main(String[] args) {
        HeroNode hero1 = new HeroNode(1, "宋江", "sd");
       HeroNode   hero2 = new HeroNode(2, "卢俊义", "ss");
        SingleLinkList singleLinkList = new SingleLinkList();
        singleLinkList.add(hero1);
        singleLinkList.add(hero2);
        singleLinkList.list();

    }
}
class   SingleLinkList{
    //创建头结点
    private   HeroNode  head=new HeroNode(0,"","");
    //添加
    public void add(HeroNode  heroNode){
        HeroNode  temp=head;
        while (true){
            if (temp.next==null){
               break;
            }
            temp=temp.next;
        }
        temp.next=heroNode;
    }
    //展示
    public  void   list(){
        if (head.next==null){
            System.out.println("链表为空");
            return;
        }
        HeroNode  temp=head.next;
        while(true){
            //判断下一个节点是否为空
            if (temp.next==null){
                break;
            }
            System.out.println(temp);
            temp=temp.next;
        }

    }

}
class   HeroNode{
    public  int  no;
    public String  name;
    public   String  nickname;
    public HeroNode  next;

    public HeroNode(int no, String name, String nickname) {
        this.no = no;
        this.name = name;
        this.nickname = nickname;
    }

    @Override
    public String toString() {
        return "HeroNode{" +
                "no=" + no +
                ", name='" + name + '\'' +
                ", nickname='" + nickname + '\'' +
                '}';
    }
}
